home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9023 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: cs.tu-berlin.de!news
  2. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: DESPERATE with Borland C++ 4.5 compiler
  5. Date: 28 Feb 1996 00:43:07 GMT
  6. Organization: Technical University of Berlin, Germany
  7. Message-ID: <4h08er$op5@news.cs.tu-berlin.de>
  8. NNTP-Posting-Host: 130.149.17.236
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=iso-8859-1
  11. Content-Transfer-Encoding: 8bit
  12.  
  13. Ali Lattunen <Ali.Lattunen@vtt.fi> writes:
  14. > Still the same problem:
  15. > Linker recognizes only one instance of template class non-inline member 
  16. > functions. If I have two template class instancies of different user
  17. > defined type as my class members, e.g.,
  18. > class MyClass {
  19. > ..
  20. >  TemplateClass<X> XMember;
  21. >  TemplateClass<Y> YMember;
  22. > };
  23. > member functions TemplateClass<Y>::XXX that are not inline are not 
  24. > recognized by the linker.
  25. > If I declare them inline, the linker works fine even if the compiler 
  26. > warns that functions cannot be expanded inline due to while-statements 
  27. > inside the function body.
  28. > How is this done right? 
  29. > How can I avoid using inline functions here?
  30. > Does Borland have any online user information service?
  31.  
  32. Well, I've had the same problem. As far as I understand this mess there is a bug 
  33. in the compiler. When you create a template class and then instantiate it the compiler 
  34. has to generate the code for the member functions. Certainly the code has to be placed 
  35. in some module. The "Smart Template" option lets the compiler select the module for the 
  36. code. Probably you can guess... this stupid thing doesn't generate the code at all ( the 
  37. inline functions run since no code needs to be generated - they are inline, aren't they ).
  38. The only solution I have found is to compile one module with the -Jgd ( Global Templates ) 
  39. option and the others with the -Jgx ( External Templates ) option. A nice side effect is 
  40. that you cannot use precompiled headers if these options are specified in the makefile or 
  41. in the project. So you have to use #pragma's after the #include's and instantiate ALL of 
  42. your template classes in ONE module or cast all those #pragma's all over your source... 
  43. it's really a mess but it works.
  44. By the way, there is one thing I don't understand. The first time I encountered this problem 
  45. I tried to compile some of the example files which deal with template and they didn't run 
  46. either. Now tell me, am I doing something wrong or don't these guys test their examples at all?
  47.  
  48. Bye
  49.  
  50. Roman
  51.